package LeetCode.month02.day60;

public class No165 {
    public int compareVersion(String version1, String version2) {
        int x = 0, y = 0;
        int left=0,right=0;
        int m = version1.length();
        int n = version2.length();
        while(left<m&&right<n){
            while(left<m&&Character.isDigit(version1.charAt(left))){
                x=x*10+(version1.charAt(left++)-'0');
            }
            while(right<n&&Character.isDigit(version2.charAt(right))){
                y=y*10+(version2.charAt(right++)-'0');
            }
            if(x>y) return 1;
            if(x<y) return -1;
            left++;
            right++;
            x=y=0;
        }
        x=y=0;
        while(left<m){
            if(version1.charAt(left)=='.') left++;
            x=x*10+(version1.charAt(left++)-'0');
            if(x>0) return 1;
        }
        while(right<n){
            if(version2.charAt(right)=='.') right++;
            y=y*10+(version2.charAt(right++)-'0');
            if(y>0) return -1;
        }
        return 0;
    }
}
